
 <script th:inline="javascript">
/*<![CDATA[*/	
	
   function loadCategory(val){
			if(val == 5){
				document.getElementById("div").style.display="";
				//转移分类
				$('#treebutton2').html($("#categorytable").find("option:selected").text() + '<i class="fa fa-angle-down"></i>');
				$("#categorytable").change(function(){$('#treebutton2').html($("#categorytable").find("option:selected").text() + '<i class="fa fa-angle-down"></i>'); });
			}else{
				document.getElementById("div").style.display="none";	
			}
			
   }

    function del(event,element){
    	event.preventDefault();
      	bootbox.confirm("您确定删除吗?", function(result) {
    	if(result){
    		var _id = $(element).attr("href").split("_")[0];
    		var _page=$(element).attr("href").split("_")[1];
    		var _viewState = $(element).attr("href").split('_')[2];
    		BOSS.remoteCall('article/list/delete',$('#div_article_list'),{id:_id,page:_page,viewState:_viewState});
    		}
    	}); 
    }
    
    function statusSingle(event,element){
    	event.preventDefault();
      	bootbox.confirm("您确定显示或隐藏吗?", function(result) {
    	if(result){
    		var _id = $(element).attr("id");
    		var _text = $(element).html();
    		if(_text=="是"){
    			_text="true";
    		}else if(_text=="否"){
    			_text="false";
    		}
    		//alert(_text);
    		//var _page=$(element).attr("href").split("_")[1];
    		//var _viewState = $(element).attr("href").split('_')[2];
    		BOSS.remoteCall('article/list/updateStateSingle',$('#div_article_list'),{id:_id,text:_text});
    		}
    	}); 
    }
	
    
    function selectAll(str)
    	{
    		if($(str).is(":checked")){
    	    		$("input[name='checkname']").attr("checked",true);
    	    		$(".checker>span").addClass("checked");
    	       }else{	
    	    		$("input[name='checkname']").attr("checked",false);
    	    		$(".checker>span").removeClass("checked");
    	     	}
    	}
    	  
	function checkValue(event,element){
		event.preventDefault();
		var _id = "1";
		var obj = document.getElementById("sel");

		var str=document.getElementsByName("checkname"); 
		var objarray=str.length;
		var _chestr="";

		
		for (i=0;i<objarray;i++)
		{
		  if(str[i].checked == true)
		  {
			  _chestr+=str[i].value+",";
		  }
		}
        if(_chestr==""){
        	alert("还没有选中项！");
        	return false;
        }


		if(obj.value == 2 && _chestr!=""){
			
	      	bootbox.confirm("您确定全部删除吗?", function(result) {
	        	if(result){
	        		var _page=$(element).attr("href").split("_")[0];
	        		var _viewState = $(element).attr("href").split('_')[1];
	        		BOSS.remoteCall('article/list/delete',$('#div_article_list'),{id:_id,page:_page,viewState:_viewState,chestr:_chestr});
	        		}
	        	}); 
			
    		
		}else if(obj.value == 3  && _chestr!=""){
			bootbox.confirm("您确定批量显示吗?", function(result) {
	        	if(result){
	        		var _status ="up";
	        		var _page=$(element).attr("href").split("_")[0];
	        		var _viewState = $(element).attr("href").split('_')[1];
	        		BOSS.remoteCall('article/list/updateState',$('#div_article_list'),{id:_id,status:_status,viewState:_viewState,chestr:_chestr});
	        		}
	        	}); 
			
		}else if(obj.value == 4 && _chestr!=""){
			bootbox.confirm("您确定批量隐藏吗?", function(result) {
	        	if(result){
	        		var _status ="down";  
	        		
	        		var _page=$(element).attr("href").split("_")[0];
	        		var _viewState = $(element).attr("href").split('_')[1];
	        		BOSS.remoteCall('article/list/updateState',$('#div_article_list'),{id:_id,page:_page,viewState:_viewState,status:_status,chestr:_chestr});
	        		}
	        	}); 
		}else if(obj.value == 5 && _chestr!=""){
			var _val = document.getElementById("categorytable");//categorytable
			var cate = _val.value;	
			bootbox.confirm("您确定要转移分类吗?", function(result) {
	        	if(result){
	        		var _status ="turn";
	        		var _page=$(element).attr("href").split("_")[0];
	        		var _viewState = $(element).attr("href").split('_')[1];
	        		BOSS.remoteCall('article/list/updateState',$('#div_article_list'),{id:_id,page:_page,viewState:_viewState,status:_status,chestr:_chestr,val:cate});
	        		}
	        	}); 
			
			
		}


    }
	
//转移分类 Start
    $('#category_tree2').jstree({
        "core" : {
            'data' : {'url' : function (node) {return '/tree/categoryArticle';}}
        }
    });
    
    $('#category_tree2').on('select_node.jstree', function(e,data) { 
    	checkCat(data.node.id);       
    });    
    
    var result;
    function getCategoryById(id,categories){   	
    	$(categories).each(function() { 
    		if(this.id == id)result = this; 
    		console.log(this.id);
	    	if(result){
	    		console.log('find it' + result);
	    		return result;
	    	}else{
	    		console.log('not find ,try sub cat' + result);
	    		result = getCategoryById(id,this.children);
	    		return result;
	    	}
    	});
		return result;
    }
    
    function addSubCategoriesToArray(category,array){
    	//console.log(category.children);
    	if(category.children){
	    	$(category.children).each(function() {
	    		console.log(this);
	    		array[array.length] = this.id;	 
	    		console.log(this.children);   		
	    		if(this.children)addSubCategoriesToArray(this.children,array);
	    	});
    	}
    }
    
    function checkCat(id){
 	   $("#categorytable option").each(function() { this.selected = (this.value == id); });
 	   $("#categorytable").change();
    }
//转移分类 End

/*]]>*/
</script>
<table layout:fragment="article_table" class="table table-striped table-bordered  table-advance table-hover" id="article_list" >
	<thead>
		<tr>
			<th><input type="checkbox" onclick="selectAll(this)"/></th>
			<th>编号</th>
			<th>文章标题</th>
			<th>文章分类</th>
			<th>文章重要性</th>
			<th>是否显示</th>
			<th>添加日期</th>
			<th>操作</th>
		</tr>
	</thead>	
	<tbody>
	
		<tr class="odd gradeX" th:each="data : ${articlePage}">
			<td>
				<input type="checkbox" name="checkname" th:attr="value=${data.id}" />	
			</td>
			<td th:text="${data.id}">
				编号
			</td>
			<td th:text="${data.title}">
				 hstyle
			</td>
			
			 <td th:text="${data.articleCategoryName}">  
			
			</td>
			<td th:text="${data.articleType}? 置顶 : 普通">
				 
			</td>
			 
			
			 <!-- <a th:href="@{'/article/list/updateStateSingle/'+${data.id}}">  -->
			 <td th:text="${data.displayed}? 是 : 否"  th:id="${data.id}" onclick="statusSingle(event,this);">
			 </td> 	
			<!--  </a> -->
		
			
			<td th:text="${data.createdDate.toLocalDate()}">
				 
			</td>	
			
			<td>
				<a href="" th:href="@{'/article/list/see/'+${data.id}}"  class="btn default btn-xs purple" th:attr="id=${'link_edit_'+dataStat.index},name=${'link_edit_'+dataStat.index}" id="Link_attributeEdit" ><i class="fa fa-edit"></i>查看</a>|
			    <a href="" th:href="@{'/article/list/edit/'+${data.id}}"  class="btn default btn-xs purple" th:attr="id=${'link_edit_'+dataStat.index},name=${'link_edit_'+dataStat.index}" id="Link_attributeEdit" ><i class="fa fa-edit"></i>编辑</a>|
                <a href="#" th:href="${data.id}+'_'+${articlePage.number}+'_'+${viewState}" th:attr="id=${'link_delete_'+dataStat.index},name=${'link_delete_'+dataStat.index}" class="btn default btn-xs purple" onclick="del(event,this);"><i class="fa fa-minus"></i>移除</a>
			</td>		 
		</tr>
	    <tr th:if="${articlePage.getNumberOfElements()==0}">
		   <td colspan="7" align="center">未查到任何记录，请放大查询条件试试</td>
		</tr> 
		
<table>
	<tr>
		<td>
			<select id='sel' onchange="loadCategory(this.value)"> 
			  <option value ="1">请选择..</option>  
			  <option value ="2">批量删除</option>  
			  <option value ="3">批量显示</option>  
			  <option value="4">批量隐藏</option>  
			  <option value="5">转移到分类</option>  
			</select>
		</td>
		
		<td>
		<!-- 	<div id="div" style="display: none" >
				<select id="categorytable" name="categorytable" >
						<option th:each="eachValue : ${categories}" th:value="${eachValue.id}" th:text="${eachValue.name}"></option>
				</select>
				<input type="hidden" id="hidden_categorytable" value="${categoryid}" />	
			</div>  -->
			
			 <div id="div" style="display: none" >
	           <!--  <select th:field="*{ArticleCategoryId}"  id="ArticleCategoryId" name="ArticleCategoryId"  style="width:250px;display:none;" th:remove="none" class="form-control"> -->
	           
	            <select id="categorytable" name="categorytable" style="width:250px;display:none;">
	            	<option value="">所有分类</option>
	                <option style="display:none"  th:each="eachValue : ${categories}"  th:value="${eachValue.id}"   th:text="${eachValue.name}"></option>
	            </select>
	            <button id="treebutton2" class="btn btn-default dropdown-toggle" type="button"  data-toggle="dropdown">
						分类 <i class="fa fa-angle-down"></i>
				</button>
				<div class="dropdown-menu dropdown-content input-large">
					<div id="category_tree2" role="menu"></div>
				</div>
					
	           <input type="hidden" id="hidden_categorytable" value="${categoryid}" />															
			</div> 
						
						
		
		</td>
		<td>
			
              <a href="#" th:href="${articlePage.number}+'_'+${viewState}" onclick="checkValue(event,this);">
                 <button> 确定</button>
              </a>
           
		</td>
	</tr>
</table>

 	</tbody>
</table>

<div th:include="page_footer" th:with="viewState=${viewState},url=${'/article/list/index'},pageContext=${articlePage}"></div>